﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


//Author: ljj
//Date: 20190627
//Function: 抛物线的追踪体攻击,将物体的高度体现到y轴上

public class Parabola : MonoBehaviour
{
    public float needTime = 1f;
    public Vector3 startPos = Vector3.zero;
    public Vector3 targetPos = Vector3.zero;
    public AoeAttack attack;
    public GameObject hitEffectPrefab;
    private float hasGone = 0.0f;
    private float gravity = 15f;

    MapManager mMapManager;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        float delta = Time.deltaTime;

        hasGone += delta;
        if (hasGone >= needTime)
        {
            attack.setTarget(targetPos);
            attack.Attack();
            if (hitEffectPrefab != null)
            {
                GameObject hitEffectObject = EffectObjectManager.Instance.CreateEffectObject(hitEffectPrefab, transform.position, Quaternion.identity);
            }
            gameObject.transform.position = new Vector3(-10, -10, 0);
            gameObject.SetActive(false);
        }

        float height = 0.5f * gravity * hasGone * (needTime - hasGone);

        Vector3 pos = startPos * (needTime - hasGone) / needTime +
            targetPos * hasGone / needTime;

        pos.y += height * 0.5f;

        pos.z = pos.y * 0.1f;

        transform.position = pos;
        

    }
}
